package com.lowca.news.util;

import java.security.SecureRandom;
import java.util.UUID;

/**
 * 封装各种生成唯一性ID算法的工具类.
 * 
 * @author calvin
 */
public class Identities {

	public enum Style {
		line, noLine;
	}

	private static SecureRandom random = new SecureRandom();

	private Identities() {
	}

	/**
	 * 封装JDK自带的UUID, 通过Random数字生成，包含-.
	 */
	public static String uuid() {
		return UUID.randomUUID().toString();

	}

	/**
	 * 封装JDK自带的UUID, 通过Random数字生成，不包含-.
	 */
	public static String uuidWithoutLine() {
		String s = UUID.randomUUID().toString();
		char[] chars = s.toCharArray();
		StringBuffer sb = new StringBuffer();
		for (char c : chars) {
			if (c != '-') {
				sb.append(c);
			}
		}
		return sb.toString();
	}

	/**
	 * 使用SecureRandom随机生成Long.
	 */
	public static long randomLong() {
		return Math.abs(random.nextLong());
	}

}
